<template>
  <view>
    <view class="searchBox">
      <my-search></my-search>
    </view>
    <!-- -轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="">
      <swiper-item v-for="(item,i) in swiperList" key="i">
        <navigator :url="'/packageA/goods_detail/goods_detail?goods_id='+item.goods_id" class="swiperNav">
          <img :src="item.image_src" />
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 分类导航 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(item,i) in navList" :key="i" @click="navClickHandler(item)">
        <image :src="item.image_src" class="nav-img" /></image>
      </view>
    </view>
    <!-- 楼层 -->
    <view class="floor-list">
      <!-- 楼层标题 -->
      <view class="floor-item" v-for="(item,i) in floorList" key="i">
        <image :src="item.floor_title.image_src" class="floor-title" mode="widthFix" />
        <!-- 楼层图片 -->
        <view class="floor-img-box">
          <navigator class="left-img-box" :url="item.product_list[0].url">
            <!-- 左侧盒子-->
            <image mode="widthFix":src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width+'rpx'}" /></image>
          </navigator>
          <!-- 右侧盒子-->
          <view class="right-img-box">
            <navigator class="right-img-item" v-for="(item1,i1) in item.product_list" :key="i1" v-if="i1 > 0"
            :url="item1.url">
              <image :src="item1.image_src" 
                class="floor-img-right" mode="widthFix" :style="{width:item1.image_width+'rpx'}"/></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>



  </view>
</template>


<style lang="scss">
  .searchBox{
    position: sticky;
    top:0;
    z-index: 9;
  }
  
  .right-img-box{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }
  .floor-img-box{
    display: flex;
  }
  .floor-img-right{
    padding-left: 10rpx;
  }
  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15px;
  }
  .nav-img {
    width: 130rpx;
    height: 140rpx;
  }
  swiper {
    height: 330rpx;

    .swiper-item,
    img {
      height: 100%;
      width: 100%;
    }
  }
  .swiperNav {
    width: 100%rpx;
    height: 330rpx;
  }
</style>

<script>
  export default {
    data() {
      return {
        swiperList: [],
        navList: [],
        floorList: []
      };
    },
    onLoad() {
      this.getSwiperList(),
        this.getNavList()
      this.getFloorList()
    },
    methods: {
      async getSwiperList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status !== 200) {
          uni.$showMsg()
          return
        }
        this.swiperList = res.message
      },
      async getNavList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status != 200) {
          uni.$showMsg()
          return
        }
        this.navList = res.message
      },
      async getFloorList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status != 200) {
          return uni.$showMsg()
        }
        // 修改url
        res.message.forEach(floor=>{
          floor.product_list.forEach(pd=>{
            pd.url = "/packageA/goods_list/goods_list?query="+pd.navigator_url.split('=')[1]
            console.log(pd.url)
          })
        })
        this.floorList = res.message
      },
      navClickHandler(ext) {
        const name = ext.name
        if (name == '分类') {
          uni.switchTab({
            url: "/pages/cate/cate"
          })
        }
      }
    }
  }
</script>